<?php echo $this->render('header.phtml'); ?>
<?php echo $this->render('menu.phtml'); ?>
<div id="content">
    <div id="icon-page" class="icon32"><br/></div><h2>编辑页面</h2>
    <div id="tabs">
        <ul>
            <li><a href="#tabs-1">列表</a></li>
            <li><a href="#tabs-2">编辑</a></li>
        </ul>
        <div id="tabs-1">
            <table class="list-table">
                <thead class="ui-state-default">
                    <tr>
                        <th width="5%">ID</th>
                        <th width="50%">标题</th>
                        <th width="15%">发布时间</th>
                        <th width="30%">操作</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if (!empty($this->pageList)) : ?>
                        <?php foreach ($this->pageList as $page) : ?>
                    <tr>
                        <td><?php echo $this->escape($page->pageId) ?></td>
                        <td><?php echo $this->escape($page->pageTitle) ?></td>
                        <td><?php echo $this->escape($page->publishTime) ?></td>
                        <td>
                            <a href="javascript:void(0)" onclick="editPage(<?php echo $this->escape($page->pageId) ?>)">编辑</a> |
                            <a href="javascript:if(confirm('确实要删除【<?php echo $this->escape($page->pageTitle) ?>】页面吗?'))location='/backend/del/page/id/<?php echo $this->escape($page->pageId) ?>'">删除</a>
                        </td>
                    </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
                <tfoot>
                    <tr class="ui-state-default">
                        <th width="10%">ID</th>
                        <th width="40%">标题</th>
                        <th width="25%">发布时间</th>
                        <th width="25%">操作</th>
                    </tr>
                </tfoot>
            </table>
            <?php if($this->pageId == 0 && !empty($this->pageList)) echo $this->paginationControl($this->pageList,'Elastic','pagebar.phtml'); ?>
        </div>
        <div id="tabs-2" class="editor-area">
            <form action="/backend/edit/page/" method="post" onsubmit="return submitForm();">
                <div class="titlebox">
                    <h3><span>标题</span></h3>
                    <input type="text" class="title" id="page_title" name="page_title" autocomplete="off" tabindex="1" size="30" value="<?php echo $this->escape($this->pageInfo->pageTitle) ?>" />
                </div>
                <div>
                    <h3><span>内容</span></h3>
                    <textarea id="page_content" name="page_content" cols="100" rows="8"><?php echo $this->escape($this->pageInfo->pageContent) ?></textarea>
                </div>
                <div id="message-box" class="ui-state-error ui-corner-all" style="display: none;padding: 12px;">
                    <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 12px;"></span>
                        <strong>警告:</strong> <span id="error-message"></span>
                    </p>
                </div>
                <div>
                    <input id="publish" type="submit" value="发布" name="publish"/>
                    <input id="pageId" name="pageId" type="hidden" value="<?php echo $this->escape($this->pageInfo->pageId) ?>" />
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript" src="/public/editor/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
    function submitForm(){
        if ($("#page_title").val() == ''){
            $("#message-box").show();
            $("#error-message").empty();
            $("#error-message").append("请输入页面标题!");
            return false;
        } else if ($("#page_content").val() == '') {
            $("#message-box").show();
            $("#error-message").empty();
            $("#error-message").append("请输入页面内容!");
            return false;
        } else{
            return true;
        }
    }

    CKEDITOR.replace('page_content',
    {
        toolbar :
            [
            ['Cut','Copy','Paste','PasteText','PasteFromWord'],
            ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
            ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
            '/',
            ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
            ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
            ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
            ['Link','Unlink','Anchor'],
            ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
            '/',
            ['Styles','Format','Font','FontSize'],
            ['TextColor','BGColor'],
            ['Maximize', 'ShowBlocks','Source']
        ],
        filebrowserBrowseUrl : '/public/editor/ckfinder/ckfinder.html',
        filebrowserImageBrowseUrl : '/public/editor/ckfinder/ckfinder.html?Type=Images',
        filebrowserFlashBrowseUrl : '/public/editor/ckfinder/ckfinder.html?Type=Flash',
        filebrowserUploadUrl : '/public/editor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
        filebrowserImageUploadUrl : '/public/editor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
        filebrowserFlashUploadUrl : '/public/editor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
    });

    $(function() {
        $("#tabs").tabs({
<?php if($this->pageId > 0): ?>
            disabled: [0],
<?php else: ?>
            disabled: [1],
<?php endif; ?>
            collapsible: true
        });
    });

    function editPage(id){
        $("#tabs").tabs('option', 'disable', []);
        window.location.href = '/backend/list/page/id/'+ id + '#tabs-' + 2;
    }
</script>
<?php echo $this->render('footer.phtml'); ?>